package com.cy.pj.sys.controller;

import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.sys.entity.SysDept;
import com.cy.pj.sys.service.SysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/dept/")
public class SysDeptController {
	@Autowired
	private SysDeptService sysDeptService;

	private String prefix = "sys";

	@RequiresPermissions("sys:dept:view")
	@GetMapping("/dept_list")
	@RequiredLog
	public String deptview()
	{
		return prefix + "/dept_list";
	}

	@RequiresPermissions("sys:dept:update")
	@GetMapping("/dept_edit")
	@RequiredLog
	public String deptaddupdateview()
	{
		return prefix + "/dept_edit";
	}

	@RequestMapping("doFindObjects")
	@ResponseBody
	@RequiredLog
	public JsonResult doFindObjects() {
		return new JsonResult(sysDeptService.findObjects());
	}


	@RequestMapping("doFindZTreeNodes")
	@ResponseBody
	public JsonResult doFindZTreeNodes() {
		return new JsonResult(sysDeptService.findZTreeNodes());
	}



	@RequestMapping("doUpdateObject")
	@ResponseBody
	public JsonResult doUpdateObject(SysDept entity){
		sysDeptService.updateObject(entity);
	    return new JsonResult("update ok");
	}

	@RequestMapping("doSaveObject")
	@ResponseBody
	public JsonResult doSaveObject(SysDept entity){
		sysDeptService.saveObject(entity);
		return new JsonResult("save ok");
	}
	@RequestMapping("doDeleteObject")
	@ResponseBody
	public JsonResult doDeleteObject(Integer id){
		sysDeptService.deleteObject(id);
		return new JsonResult("delete ok");
	}
}
